package com.vtest.mes.task.autopkl;

import com.vtest.mes.domain.CQLAutoPKLEntity;
import com.vtest.mes.utils.ExcelUtils;
import com.vtest.mes.utils.FileUtils;
import com.vtest.mes.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.jni.Directory;

import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @program: MesHelper
 * @author: tiger
 * @create: 2024-12-10 14:47
 * @Description : CQL自动出货
 */

@Slf4j
public class CQLAutoPKL {



    /**
     * @Description: 自动出货
     * @Date 2024/12/10 14:51
     */
    public void AutoPKL() {
        log.info("CQL自动出货开始执行");
        String path = "\\\\195.170.13.161\\Files\\CQLAutoPKL";
        String pathSuccess = "\\\\195.170.13.161\\Files\\CQLAutoPKL\\Success\\";
        String pathError = "\\\\195.170.13.161\\Files\\CQLAutoPKL\\Error\\";
        File directory = new File(path);
        if (!FileUtils.isDirectory(path)) {
            log.warn("不存在该路径或者该路径不是目录 {}", path);
            return;
        }
        File[] badgeIDDirNums = directory.listFiles();

        for (File badgeIDDir : badgeIDDirNums) {
            if (badgeIDDir.getName().contains("Success") || badgeIDDir.getName().contains("Error")) continue;

            File[] excelFileNums = badgeIDDir.listFiles();
            String badgeID = StringUtils.getSplitStringLast(badgeIDDir.getName(), "\\");
            for (File excelFile : excelFileNums) {
                if (!FileUtils.isFile(excelFile)) {
                    log.warn("不存在该路径或者该路径不是文件 {}", excelFile.getPath());
                    continue;
                }
                if (!excelFile.getName().endsWith(".xlsx")) {
                    log.warn("该文件不是excel文件 {}", excelFile.getPath());
                    continue;
                }
                List<CQLAutoPKLEntity> cqlAutoPKLList = ExcelUtils.excel2List(excelFile.getName(), CQLAutoPKLEntity.class);


                String customCode = cqlAutoPKLList.get(0).getCode();

                LocalDateTime date = LocalDateTime.now();
                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
                String tempTrackNum = customCode + date.format(dateTimeFormatter);



            }
        }

    }

    public static void main(String[] args) {
        CQLAutoPKL cqlAutoPKL = new CQLAutoPKL();
        cqlAutoPKL.AutoPKL();
    }
}
